package com.hugo.maomi_first.zhuanti.presenter;

import com.hugo.maomi_first.base.BasePresenter;
import com.hugo.maomi_first.bean.ZhuanTiBean;
import com.hugo.maomi_first.bean.ZhuanTiDetailBean;
import com.hugo.maomi_first.bean.ZhuanTiHeaderBean;
import com.hugo.maomi_first.zhuanti.model.ModelFactory;
import com.hugo.maomi_first.zhuanti.model.ZhuanTiModel;
import com.hugo.maomi_first.zhuanti.view.IZhuantiView;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2016/7/5.
 */
public class ZhuanTiPresenterImpl extends BasePresenter<IZhuantiView> implements IZhuanTiPresenter {

    private ZhuanTiModel zhuanTiModel;


    @Override
    public void getZhuanTiHeaderData() {
        ModelFactory.getFindModel().getHeaderData(new Callback<ZhuanTiHeaderBean>() {
            @Override
            public void onResponse(Call<ZhuanTiHeaderBean> call, Response<ZhuanTiHeaderBean> response) {
                ZhuanTiHeaderBean body = response.body();
                if (body !=null){
                    ZhuanTiHeaderBean.DataBean data = body.getData();
                    List<ZhuanTiHeaderBean.DataBean.ItemsBean> list=data.getItems();
                    getView().onLoadHeader(list);
                }
            }

            @Override
            public void onFailure(Call<ZhuanTiHeaderBean> call, Throwable t) {

            }
        });
    }

    @Override
    public void getZhuanTiData(int pager) {
        ModelFactory.getFindModel().getDetailData(pager, new Callback<ZhuanTiBean>() {
            @Override
            public void onResponse(Call<ZhuanTiBean> call, Response<ZhuanTiBean> response) {
                ZhuanTiBean body = response.body();
                if (body!=null){
                    ZhuanTiBean.DataBean data = body.getData();
                    List<ZhuanTiBean.DataBean.ItemsBean> list=data.getItems();
                    getView().onLoadDetail(list);

                }
            }

            @Override
            public void onFailure(Call<ZhuanTiBean> call, Throwable t) {

            }
        });
    }

    @Override
    public void getZhuanTiDeatail(int id) {
        ModelFactory.getFindModel().getZhuanTiDetailData(id, new Callback<ZhuanTiDetailBean>() {
            @Override
            public void onResponse(Call<ZhuanTiDetailBean> call, Response<ZhuanTiDetailBean> response) {

                ZhuanTiDetailBean body = response.body();
                if (body != null) {
                    ZhuanTiDetailBean.DataBean data = body.getData();
                    getView().onLoadZhuanTiDetail(data);
                }
            }

            @Override
            public void onFailure(Call<ZhuanTiDetailBean> call, Throwable t) {

            }
        });
    }


}
